package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwSceincMerchanttypeService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by BKWJA on 2018/12/21.
 * 景区商户类型控制层
 */
@Slf4j
@RequestMapping("SceMerType")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwSceincMerchanttypeController  extends IMoocExceptionHandler {

    @Autowired
    private XwSceincMerchanttypeService xwSceincMerchanttypeService;

    //获取全部的景区类型信息列表,不分页，按添加日期排序
    @RequestMapping("/getAllSerMertype")
    @ResponseBody
    public JSONObject getAllSerMertype(){
        return  xwSceincMerchanttypeService.getAllSerMertype();
    }


    /**
     * 景区商户类型列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @RequestMapping("/getSceMertypelist")
    @ResponseBody
    public JSONObject getSceMertypelist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                      @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "sortfild",defaultValue = "sceincType_createtime") String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway){
        return xwSceincMerchanttypeService.getSceMertypelist(pageindex,pagesize,starttime,endtime,sortfild,sortway);
    }

    /**
     * 修改，新增景区商户类型信息
     * @param sceincType_encryptId  景区商户类型加密id
     * @param sceincType_desc 景区商户类型文字
     * @return
     */
    @RequestMapping("/updateSceMertype")
    @ResponseBody
    public JSONObject updateSceMertype(String sceincType_encryptId,String sceincType_desc){
        return xwSceincMerchanttypeService.updateSceMertype(sceincType_encryptId,sceincType_desc);
    }

    /**
     * 根据farm_playType_encryptId景区商户类型加密id，删除对应的记录
     * @param sceincType_encryptId
     * @return
     */
    @RequestMapping("/delSceMertype")
    @ResponseBody
    public JSONObject delSceMertype(String sceincType_encryptId){
        return xwSceincMerchanttypeService.delSceMertype(sceincType_encryptId);
    }

}
